<?php
/* SVN FILE: $Id: village.php 17 2009-04-20 02:00:59Z ake.svedin $ */
/**
 * Travian Alliance Coordinator
 * Copyright (c) 2009 Åke Svedin.
 *
 * This file is part of Travian Alliance Coordinator.
 *
 * Travian Alliance Coordinator is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Travian Alliance Coordinator is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Travian Alliance Coordinator.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author $Author: ake.svedin $
 * @copyright Copyright (c) 2009 Åke Svedin.
 * @version $Revision: 17 $
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3
 */
class Village extends AppModel {

    var $name = 'Village';
    var $validate = array(
        'x' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', -400, 400),
                'message' => 'The coordinate is not within the allowed range (-400 to 400)'
            ),
        ),
        'y' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', -400, 400),
                'message' => 'The coordinate is not within the allowed range (-400 to 400)'
            ),
        ),
        'name' => array('notempty'),
        'population' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('comparisom', '=>', 0),
                'message' => 'This must be atleast zero'
            ),
        ),
        'type' => array(
            'min' => array(
                'rule' => array('comparison', '>=', 1)
            ),
            'max' => array(
                'rule' => array('comparison', '<=', 3)
            ),
        ),
        'wall' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', 0, 20),
                'message' => 'This must be between 0 and 20'
            ),
        ),
        'tournament' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', 0, 20),
                'message' => 'This must be between 0 and 20'
            ),
        ),
        'palace' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', 0, 20),
                'message' => 'This must be between 0 and 20'
            ),
        ),
        'silo' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', 0, 20),
                'message' => 'This must be between 0 and 20'
            ),
        ),
        'crop' => array(
            'numerical' => array(
                'rule' => 'numeric',
                'message' => 'This is not a valid number'
            ),
            'range' => array(
                'rule' => array('range', 0, 20),
                'message' => 'This must be between 0 and 20'
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'MapVillage' => array(
            'className' => 'MapVillage',
            'foreignKey' => 'map_village_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

    var $hasOne = array(
        'Hero' => array(
            'className' => 'Hero',
            'foreignKey' => 'village_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Troop' => array(
            'className' => 'Troop',
            'foreignKey' => 'village_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

}
?>